<template>
 <div>
  <el-table :data="tableData" :height="tableHeight" style="width: 100%"
    class="tableClass2" highlight-current-row
    >
    <el-table-column
      type="index"
      width="40">
    </el-table-column>
    <el-table-column width="120px" >
      <template slot-scope="scope">
        <el-button size="mini" type="primary" plain @click="handleClickPush(scope.row)">打板({{scope.row.num}})</el-button>
      </template>
    </el-table-column>
    <el-table-column prop="type"                label="仓库类型"      width="90px"></el-table-column>
    <el-table-column prop="address"             label="存放地址"      width="160px" ></el-table-column>
    <el-table-column prop="members"             label="项目关联"      width="200px"></el-table-column>
    <el-table-column prop="lastChangeTime"      label="最后提交时间"  width="120px"></el-table-column>
    <el-table-column prop="lastChangeUserName"  label="最后提交人"    width="120px"></el-table-column>
    <el-table-column label="状态" width="120px" >
      <template slot-scope="scope">
        <el-tag :type="statusType(scope.row.status)" effect="dark">{{statusTypeName(scope.row.status)}}</el-tag>
      </template>
    </el-table-column>
    <el-table-column label="操作" width="150">
      <template slot-scope="scope">
        <el-button @click="handleEdit(scope.row)" type="text" size="small" style="margin-top: -10px">修改</el-button>
        <el-button @click="handleChangeStatus(scope.row)" type="text" size="small" style="margin-top: -10px">展示/不展示</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- <div class="block">
    <el-pagination
      style="margin-top: 10px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.pageNum"
      :page-sizes="[10, 20, 50]"
      :page-size="10"
      layout="total, sizes, prev, pager, next"
      background
      :total="page.totalNum">
    </el-pagination>
  </div> -->
  <SubmitPop ref="SubmitPop" />
 </div>
</template>

<script>
  import {changeStatus} from '@/api/repository'
  import SubmitPop from './submitPop'
  export default {
    data() {
      return {
        tableHeight: 550,
        height: `${document.documentElement.clientHeight}`,
        loading: false,
        showTran: false,
        page: {
          pageNum: 1,
          pageSize: 10,
          totalNum: 0,
          totalPage: 0
        },
        tableData: []
      }
    },
    methods: {
      handleClickPush(row) {
        this.$refs['SubmitPop'].showPop(row)
      },
      changeStatus(taskId, process, status) {
        for (var i=0; i<this.tableData.length; i++) {
          if (this.tableData[i].taskId===taskId) {
            this.tableData[i].status = status
            this.tableData[i].process = process
          }
        }
      },
      statusType(type) {
        switch(type) {
          case 0:
            return 'success'
          case 1:
            return 'info'
        }
      },
      statusTypeName(type) {
        switch(type) {
          case 0:
            return '展示'
          case 1:
            return '不展示'
        }
      },
      getTableData(data) {
        this.tableData = data
      },
      handleSizeChange(value) {
        this.page.pageSize = value
        this.$parent.$refs.search.handleClickSearch()
      },
      handleCurrentChange(value) {
        this.page.pageNum = value
        this.$parent.$refs.search.handleClickSearch()
      },
      handleEdit(row) {
        this.$parent.$refs.search.$refs.pop.clickNew(row)
      },
      handleChangeStatus(row) {
        let status = row.status
        let info = status===0?'是否不展示此条数据':'是否展示此条数据'
        this.$confirm(info, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          changeStatus(row.crId).then(_ => {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.$parent.$refs['search'].handleClickSearch()
          })
        }).catch(error => {})
      },
    },
    components: {
      SubmitPop
    },
    created() {
      this.height>900?this.tableHeight=860:550
    },
  }
</script>

<style>
  .tableClass2 {

  }
  .myPop>.el-popover.popverClass {
    padding-top: 9px !important;
    padding-bottom: 8px !important;
    padding-left: 2px !important;
    border: 0px !important;
    background: #F5F7FA !important;
    -webkit-box-shadow: none !important;
    box-shadow: none;
    float: right;
    margin-top: -12px;
    margin-left: 20px;
  }
  td.el-table_1_column_8 {
    padding-top: 0px !important;
    padding-bottom: 0px !important;
  }
</style>
